﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 尺寸下发
    /// </summary>
    public partial class SpecAssign : BusEntity
    {
        /// <summary>
        /// BomId
        /// </summary>
        public string BomId { get; set; }
        /// <summary>
        /// 物料大类
        /// </summary>
        public string MaterialId { get; set; }
        /// <summary>
        /// 物料规格
        /// </summary>
        public string SpecId { get; set; }
        /// <summary>
        /// 下发数据类型
        /// 直径,宽度,高度,至工装高,边长
        /// </summary>
        public string AssignType { get; set; }
    }

    public partial class SpecAssign : BusEntity
    {
        /// <summary>
        /// MaterialBom
        /// </summary>
        public MaterialBom Bom { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public MaterielInfor Material { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public MaterielSpec Spec { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public List<SpecAssignDetail> AssignDetail { get; set; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class SpecAssignTypeConfig : BusEntityTypeConfig<SpecAssign>, IEntityTypeConfiguration<SpecAssign>
    {
        public override void Configure(EntityTypeBuilder<SpecAssign> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Bom).WithMany().HasForeignKey(p => p.BomId);
            builder.HasOne(p => p.Material).WithMany().HasForeignKey(p => p.MaterialId);
            builder.HasOne(p => p.Spec).WithMany().HasForeignKey(p => p.SpecId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.BomId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.MaterialId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.SpecId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.AssignType).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("尺寸下发");
            builder.Property(p => p.BomId).HasComment("BomId");
            builder.Property(p => p.MaterialId).HasComment("名物料大类称");
            builder.Property(p => p.SpecId).HasComment("物料规格");
            builder.Property(p => p.AssignType).HasComment("下发数据类型");
            #endregion

            #region 种子数据
            #endregion
        }
    }
}
